'''
Created on 03-Apr-2010

@author: darsh
'''
from Util import util
from Util.util import debugmsg
import os
from Widgets.FrameWidget import FrameWidget

class CommandExecutor():
    """
    This contains auxiliary functions that map directly to the commands specified in the config file
    """
    def __init__(self):
        pass


    def Execute(self, command, args):
        debugmsg("TRYING COMMAND %s " % command)
        debugmsg("WITH ARGUMENTS %s " % args)
        commandtoexecute = getattr(self, command)
        if not commandtoexecute:
            debugmsg("INVALID COMMAND %s " % command)
            debugmsg("INVALID COMMAND SPECIFIED" % args)
            return
        commandtoexecute(args)


    def run(self, args):
        os.system(args + "&")

    def message(self, args):
        util.message(args)


    def sendtodesktop(self, args):
        win = self.getfocusedwindow(self.currentdesktop)
        if win is not None:
            self.sendwindowtodesktop(win, args)
            

    def togglemaximize(self, args):
        win = self.getfocusedwindow(self.currentdesktop)
        if self.CLIENTS.has_key(win):
            self.CLIENTS[win].togglemaximize()
            

    def togglefullscreen(self, args):
        win = self.getfocusedwindow(self.currentdesktop)
        if self.CLIENTS.has_key(win):
            self.CLIENTS[win].togglefullscreen()    
    

    def moveleft(self, args):
        win = self.getfocusedwindow(self.currentdesktop)
        if self.CLIENTS.has_key(win):
            self.CLIENTS[win].moveleft(args)
                
    def moveright(self, args):
        win = self.getfocusedwindow(self.currentdesktop)
        if self.CLIENTS.has_key(win):
            self.CLIENTS[win].moveright(args)
                
    def movetop(self, args):
        win = self.getfocusedwindow(self.currentdesktop)
        if self.CLIENTS.has_key(win):
            self.CLIENTS[win].movetop(args)
    
    def shrinkbottom(self, args):
        win = self.getfocusedwindow(self.currentdesktop)
        if self.CLIENTS.has_key(win):
            self.CLIENTS[win].shrinkbottom(args)

    def shrinkleft(self, args):
        win = self.getfocusedwindow(self.currentdesktop)
        if self.CLIENTS.has_key(win):
            self.CLIENTS[win].shrinkleft(args)
                    
    def shrinkright(self, args):
        win = self.getfocusedwindow(self.currentdesktop)
        if self.CLIENTS.has_key(win):
            self.CLIENTS[win].shrinkright(args)
                
    def shrinktop(self, args):
        win = self.getfocusedwindow(self.currentdesktop)
        if self.CLIENTS.has_key(win):
            self.CLIENTS[win].shrinktop(args)
    
    def movebottom(self, args):
        win = self.getfocusedwindow(self.currentdesktop)
        if self.CLIENTS.has_key(win):
            self.CLIENTS[win].movebottom(args)

    def growbottom(self, args):
        win = self.getfocusedwindow(self.currentdesktop)
        if self.CLIENTS.has_key(win):
            self.CLIENTS[win].growbottom(args)

    def growleft(self, args):
        win = self.getfocusedwindow(self.currentdesktop)
        if self.CLIENTS.has_key(win):
            self.CLIENTS[win].growleft(args)
                   
    def growright(self, args):
        win = self.getfocusedwindow(self.currentdesktop)
        if self.CLIENTS.has_key(win):
            self.CLIENTS[win].growright(args)
               
    def growtop(self, args):
        win = self.getfocusedwindow(self.currentdesktop)
        if self.CLIENTS.has_key(win):
            self.CLIENTS[win].growtop(args)